﻿using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Terraria.GameContent;
using Terraria.ID;

namespace Terraria.ModLoader
{
	// Token: 0x020001D8 RID: 472
	public class ModGore
	{
		// Token: 0x06001363 RID: 4963 RVA: 0x00410798 File Offset: 0x0040E998
		internal static int ReserveGoreID()
		{
			int result = ModGore.nextGore;
			ModGore.nextGore++;
			return result;
		}

		// Token: 0x06001364 RID: 4964 RVA: 0x0000FDD3 File Offset: 0x0000DFD3
		public static int GetGoreSlot(string texture)
		{
			if (ModGore.gores.ContainsKey(texture))
			{
				return ModGore.gores[texture];
			}
			return 0;
		}

		// Token: 0x06001365 RID: 4965 RVA: 0x004107B8 File Offset: 0x0040E9B8
		internal static void ResizeAndFillArrays()
		{
			Array.Resize<bool>(ref Main.goreLoaded, ModGore.nextGore);
			Array.Resize<Texture2D>(ref Main.goreTexture, ModGore.nextGore);
			Array.Resize<bool>(ref ChildSafety.SafeGore, ModGore.nextGore);
			Array.Resize<int>(ref GoreID.Sets.SpecialAI, ModGore.nextGore);
			Array.Resize<int>(ref GoreID.Sets.DisappearSpeed, ModGore.nextGore);
			Array.Resize<int>(ref GoreID.Sets.DisappearSpeedAlpha, ModGore.nextGore);
			for (int i = 1087; i < ModGore.nextGore; i++)
			{
				Main.goreLoaded[i] = true;
				GoreID.Sets.DisappearSpeed[i] = 1;
				GoreID.Sets.DisappearSpeedAlpha[i] = 1;
			}
			foreach (string text in ModGore.gores.Keys)
			{
				Main.goreTexture[ModGore.gores[text]] = ModLoader.GetTexture(text);
			}
		}

		// Token: 0x06001366 RID: 4966 RVA: 0x0000FDEF File Offset: 0x0000DFEF
		internal static void Unload()
		{
			ModGore.gores.Clear();
			ModGore.modGores.Clear();
			ModGore.nextGore = 1087;
		}

		// Token: 0x06001367 RID: 4967 RVA: 0x0000FE0F File Offset: 0x0000E00F
		internal static void SetupGore(Gore gore)
		{
			if (ModGore.modGores.ContainsKey(gore.type))
			{
				gore.modGore = ModGore.modGores[gore.type];
				gore.modGore.OnSpawn(gore);
				return;
			}
			gore.modGore = null;
		}

		// Token: 0x06001368 RID: 4968 RVA: 0x0000FE4D File Offset: 0x0000E04D
		internal static void SetupUpdateType(Gore gore)
		{
			if (gore.modGore != null && gore.modGore.updateType > 0)
			{
				gore.realType = gore.type;
				gore.type = gore.modGore.updateType;
			}
		}

		// Token: 0x06001369 RID: 4969 RVA: 0x0000FE82 File Offset: 0x0000E082
		internal static void TakeDownUpdateType(Gore gore)
		{
			if (gore.realType > 0)
			{
				gore.type = gore.realType;
				gore.realType = 0;
			}
		}

		// Token: 0x0600136A RID: 4970 RVA: 0x004108A0 File Offset: 0x0040EAA0
		internal static bool DrawBackGore(Gore gore)
		{
			if (gore.modGore != null)
			{
				return gore.modGore.DrawBehind(gore);
			}
			return ((gore.type >= 706 && gore.type <= 717) || gore.type == 943) && (gore.frame < 7 || gore.frame > 9);
		}

		// Token: 0x0600136B RID: 4971 RVA: 0x00006B58 File Offset: 0x00004D58
		public virtual void OnSpawn(Gore gore)
		{
		}

		// Token: 0x0600136C RID: 4972 RVA: 0x00008CF7 File Offset: 0x00006EF7
		public virtual bool Update(Gore gore)
		{
			return true;
		}

		// Token: 0x0600136D RID: 4973 RVA: 0x00404FFC File Offset: 0x004031FC
		public virtual Color? GetAlpha(Gore gore, Color lightColor)
		{
			return null;
		}

		// Token: 0x0600136E RID: 4974 RVA: 0x0000ADF8 File Offset: 0x00008FF8
		public virtual bool DrawBehind(Gore gore)
		{
			return false;
		}

		// Token: 0x04001465 RID: 5221
		private static int nextGore = 1087;

		// Token: 0x04001466 RID: 5222
		internal static readonly IDictionary<string, int> gores = new Dictionary<string, int>();

		// Token: 0x04001467 RID: 5223
		internal static readonly IDictionary<int, ModGore> modGores = new Dictionary<int, ModGore>();

		// Token: 0x04001468 RID: 5224
		public int updateType = -1;
	}
}
